//
//  Factory.swift
//  TravelNotes
//
//  Created by 千锋 on 16/8/15.
//  Copyright © 2016年 胡光健. All rights reserved.
//

import UIKit


class Factory: NSObject {
    
    // UIView
    static func createViewWith(frame: CGRect) -> UIView {
        let view = UIView(frame: frame)
        return view
    }
    // UILabel
    static func createLabelWith(frame: CGRect, text: String, font: UIFont, textAlignment: NSTextAlignment, textColor: UIColor)-> UILabel {
        
        let label = UILabel(frame: frame)
        label.text = text
        label.textColor = textColor
        label.textAlignment = textAlignment
        label.font = font
        
        return label
    }
    // UIButton
    static func createButtonWith(frame: CGRect, type: UIButtonType, title: String, titleColor: UIColor, target: AnyObject?, imageName: String, action: Selector, backgroundImageName: String) -> UIButton {
        let button = UIButton(type: type)
        button.frame = frame
        button.setTitle(title, forState: .Normal)
        
        button.setTitleColor(titleColor, forState: .Normal)
        
        button.setImage(UIImage(named: imageName), forState: .Normal)
       
        button.setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)

        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        return button
    }
    // UIImageView
    static func createImageViewWith(frame: CGRect,imageName: String) -> UIImageView {
        let imageView = UIImageView(frame: frame)
        imageView.image = UIImage(named: imageName)
        
        return imageView
    }
    // UITextField
    static func createTextFieldWith(frame: CGRect, text: String, placeholder: String) -> UITextField {
        let textField = UITextField(frame: frame)
        textField.text = text
        textField.placeholder = placeholder
        
        return textField
    }
}
